18 Lecture

CS201

Midterm & Final Term Short Notes

Files

Files in C programming are used for input and output operations. A file is a collection of related information that is stored on the disk of the computer. The standard I/O library in C provides functions like fopen(), fclose(), fread(), fwrite()


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which function is used to open a file in C? a) fopen() b) close() c) read() d) write() Answer: a) fopen()

  2. Which mode is used to open a file for writing in C? a) "r" b) "w" c) "a" d) "x" Answer: b) "w"

  3. What is the syntax for opening a file in read mode? a) fopen("filename", "r") b) fopen("r", "filename") c) fopen("filename", read) d) fopen(read, "filename") Answer: a) fopen("filename", "r")

  4. Which function is used to close a file in C? a) close() b) fclose() c) endfile() d) finish() Answer: b) fclose()

  5. Which function is used to write data to a file in C? a) fread() b) fwrite() c) fprintf() d) printf() Answer: b) fwrite()

  6. Which mode is used to open a file for appending data in C? a) "r" b) "w" c) "a" d) "x" Answer: c) "a"

  7. What is the syntax for opening a file in write mode? a) fopen("filename", "w") b) fopen("w", "filename") c) fopen("filename", write) d) fopen(write, "filename") Answer: a) fopen("filename", "w")

  8. Which function is used to read data from a file in C? a) fread() b) fwrite() c) fprintf() d) printf() Answer: a) fread()

  9. Which function is used to move the file pointer to a specific position within the file? a) fpos() b) fseek() c) fmove() d) fshift() Answer: b) fseek()

  10. Which mode is used to open a file for both reading and writing in C? a) "r+" b) "w+" c) "a+" d) "x+" Answer: a) "r+"



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a file in computer science, and how is it used? Answer: A file is a collection of data or information that is stored in a computer system. It is used to store, access, and manage information in an organized manner.

  2. What is the difference between text and binary files? Answer: Text files contain human-readable characters, while binary files contain machine-readable data in the form of bytes. Text files are used to store textual data such as documents and source code, while binary files are used to store non-textual data such as images, videos, and executables.

  3. What are the different file modes in C programming language? Answer: The different file modes in C programming language are read mode ('r'), write mode ('w'), append mode ('a'), and read-write mode ('r+').

  4. What is the difference between fopen() and fclose() functions in C programming? Answer: The fopen() function is used to open a file, while the fclose() function is used to close an open file.

  5. What is the use of fseek() function in C programming? Answer: The fseek() function is used to set the file pointer to a specific position within the file.

  6. How can you check if a file exists in C programming? Answer: The access() function can be used to check if a file exists in C programming.

  7. What is the difference between feof() and ferror() functions in C programming? Answer: The feof() function is used to check if the end of a file has been reached, while the ferror() function is used to check if an error has occurred during file operations.

  8. How can you read a line from a file in C programming? Answer: The fgets() function can be used to read a line from a file in C programming.

  9. What is the difference between fread() and fwrite() functions in C programming? Answer: The fread() function is used to read data from a file, while the fwrite() function is used to write data to a file.

  10. What is buffering in file I/O operations? Answer: Buffering refers to the process of temporarily storing data in a memory buffer before writing it to a file or reading it from a file. This is done to improve the performance of file I/O operations.

In computer science, a file is a resource for storing data. A file is identified by a filename and a path, and it can have different types, such as text, binary, or executable. File manipulation in C++ involves opening a file, reading from it, writing to it, and closing it. There are different modes of file handling, such as read-only, write-only, and read-write. C++ provides a set of functions and classes for file manipulation, such as fstream, ifstream, and ofstream. The fstream class is the most versatile, as it allows both reading and writing to a file. File handling in C++ can be a powerful tool for data storage and retrieval, as well as for data analysis and processing. However, it requires proper error handling and memory management to avoid issues such as file corruptionIn computer science, a file is a resource for storing data. A file is identified by a filename and a path, and it can have different types, such as text, binary, or executable. File manipulation in C++ involves opening a file, reading from it, writing to it, and closing it. There are different modes of file handling, such as read-only, write-only, and read-write. C++ provides a set of functions and classes for file manipulation, such as fstream, ifstream, and ofstream. The fstream class is the most versatile, as it allows both reading and writing to a file. File handling in C++ can be a powerful tool for data storage and retrieval, as well as for data analysis and processing. However, it requires proper error handling and memory management to avoid issues such as file corruption or data loss. or data loss.